package cn.test;

import org.joor.jdk6.Reflect;

public class JoorDemo {
    public static void main(String[] args) {
        hookWord();
        hookInterface();
    }

    private static void hookWord() {
        String world = Reflect.on("java.lang.String")  // Like Class.forName()
                .create("Hello World") // Call most specific matching constructor
                .call("substring", 6)  // Call most specific matching substring() method
                .call("toString")      // Call toString()
                .get();                // Get the wrapped object, in this case a String
        System.out.println("hookWord: "+world);
    }
    
    private static void hookInterface(){
        String substring = Reflect.on("java.lang.String")
                .create("Hello World")
                .as(StringProxy.class) // Create a proxy for the wrapped object
                .substring(6);         // Call a proxy method
        System.out.println("hookInterface: "+substring);
    }
    
    public interface StringProxy {
        String substring(int beginIndex);
      }

     

}
